package fiveson;

import java.awt.*;

public class Poniter {
    //对象数组索引
    private int i = 0,j = 0;
    //对象数组坐标
    private int x = 0,y = 0;
    //高度
    private int h = 40;
    //是否显示
    private boolean isShow = false;


    public Poniter(int i, int j, int x, int y) {
        this.i = i;
        this.j = j;
        this.x = x;
        this.y = y;
    }

    public void draw(Graphics g) {
        g.setColor(new Color(255, 0, 0));
        if (isShow) {
            drawPionter(g);
        }
    }

    private void drawPionter(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setStroke(new BasicStroke(2.0f));
        int x1 = 0;
        int x2 = 0;
        int y1 = 0;
        int y2 = 0;
        x1 = this.x - h / 2;
        y1 = this.y - h / 2;

        x2 = x1 + h / 4;
        y2 = y1;
        g2d.drawLine(x1, y1, x2, y2);

        x2 = x1;
        y2 = y1 + h / 4;
        g2d.drawLine(x1, y1, x2, y2);

        x1 = this.x + h / 2;
        y1 = this.y - h / 2;

        x2 = x1 - h / 4;
        y2 = y1;
        g2d.drawLine(x1, y1, x2, y2);

        x2 = x1;
        y2 = y1 + h / 4;
        g2d.drawLine(x1, y1, x2, y2);

        x1 = this.x + h / 2;
        y1 = this.y + h / 2;

        x2 = x1 - h / 4;
        y2 = y1;
        g2d.drawLine(x1, y1, x2, y2);

        x2 = x1;
        y2 = y1 - h / 4;
        g2d.drawLine(x1, y1, x2, y2);

        x1 = this.x - h / 2;
        y1 = this.y + h / 2;

        x2 = x1 + h / 4;
        y2 = y1;
        g2d.drawLine(x1, y1, x2, y2);

        x2 = x1;
        y2 = y1 - h / 4;
        g2d.drawLine(x1, y1, x2, y2);
    }

    public boolean isPoint(int x, int y) {
        int x1 = this.x - h / 2;
        int y1 = this.y - h / 2;
        int x2 = this.x + h / 2;
        int y2 = this.y + h / 2;
        return x > x1 && y > y1 && x < x2 && y < y2;
    }

    public boolean isShow() {
        return isShow;
    }

    public void setShow(boolean show) {
        isShow = show;
    }
}
